{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "cd703192",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "2c616d9a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'1.5.3'"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pandas.__version__  # 查看版本"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "971afb91",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0    1\n",
      "1   -2\n",
      "2    3\n",
      "3   -4\n",
      "dtype: int64\n"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "#仅有一个数组构成\n",
    "obj = pd.Series([1, -2, 3, -4])\n",
    "print(obj)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "eb595505",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "a    2\n",
      "c    4\n",
      "d    5\n",
      "e    7\n",
      "Name: age, dtype: int64\n"
     ]
    }
   ],
   "source": [
    "i = [\"a\", \"c\", \"d\", \"e\"]\n",
    "v = [2, 4, 5, 7]\n",
    "t = pd.Series(v, index = i, name = \"age\")\n",
    "print(t)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "ab4405c2",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  name     sex  year city\n",
      "0   张三  female  2001   北京\n",
      "1   李四  female  2001   上海\n",
      "2   王五    male  2003   广州\n",
      "3   小明    male  2002   北京\n"
     ]
    }
   ],
   "source": [
    "data = {\n",
    "    'name':['张三', '李四', '王五', '小明'],\n",
    "    'sex':['female', 'female', 'male', 'male'],\n",
    "    'year':[2001, 2001, 2003, 2002],\n",
    "    'city':['北京', '上海', '广州', '北京'] }\n",
    "df = pd.DataFrame(data)\n",
    "print(df)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "eb5b42c2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>sex</th>\n",
       "      <th>year</th>\n",
       "      <th>city</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>张三</td>\n",
       "      <td>female</td>\n",
       "      <td>2001</td>\n",
       "      <td>北京</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>李四</td>\n",
       "      <td>female</td>\n",
       "      <td>2001</td>\n",
       "      <td>上海</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>王五</td>\n",
       "      <td>male</td>\n",
       "      <td>2003</td>\n",
       "      <td>广州</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>小明</td>\n",
       "      <td>male</td>\n",
       "      <td>2002</td>\n",
       "      <td>北京</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  name     sex  year city\n",
       "0   张三  female  2001   北京\n",
       "1   李四  female  2001   上海\n",
       "2   王五    male  2003   广州\n",
       "3   小明    male  2002   北京"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "a293942b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  name     sex  year city\n",
      "a   张三  female  2001   北京\n",
      "b   李四  female  2001   上海\n",
      "c   王五    male  2003   广州\n",
      "d   小明    male  2002   北京\n"
     ]
    }
   ],
   "source": [
    "df3 = pd.DataFrame(data, index = ['a', 'b', 'c', 'd'])\n",
    "print(df3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7d4f4166",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.4"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": false,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
